<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="/resources/template/template.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui"
                xmlns:f="http://java.sun.com/jsf/core">

    <ui:define name="content">
        <h:panelGroup >
            <h:form id="form"  >

                <p:panel header="Manage Service Fees" >

                    <h:panelGrid columns="1" >
                        <h:panelGrid columns="2" >
                            <h:outputLabel value="Select Service" />
                            <p:autoComplete converter="timedIt" 
                                            forceSelection="true"  
                                            value="#{timedItemFeeController.currentIx}" 
                                            completeMethod="#{timedItemController.completeInvest}" 
                                            var="ix" itemLabel="#{ix.name}" 
                                            itemValue="#{ix}" 
                                            size="30"
                                            style="width: 400px;">
                                <p:ajax event="itemSelect" process="@this" update="gpDetail" listener="#{timedItemFeeController.fillCharges()}"></p:ajax>
                            </p:autoComplete>
                        </h:panelGrid>

                        <h:panelGrid id ="gpVeda" columns="2" styleClass="alignTop" >
                            <p:panel id="gpDetail" >
                                <f:facet name="header" >
                                    <h:outputLabel value="Charge Detail" ></h:outputLabel>
                                    <h:outputText style="float:right;" id="lblTotal" value="Total : #{timedItemFeeController.currentIx.total}"/>
                                </f:facet>
                                <h:panelGrid columns="2">
                                    <h:outputText value="Fee Name"/>
                                    <h:inputText autocomplete="off" id="txtFeeName" value="#{timedItemFeeController.currentFee.name}"/>
                                    <h:outputText value="Fee Type"/>
                                    <h:selectOneListbox id="cmbFeeType" size="1" value="#{timedItemFeeController.currentFee.feeType}" >
                                        <f:selectItem itemLabel="Please select the type"/>
                                        <f:selectItem itemLabel="Staff Fee" itemValue="Staff" />
                                        <f:selectItem itemLabel="Hospital Fee" itemValue="OwnInstitution" />
                                        <f:selectItem itemLabel="Outside Fee" itemValue="OtherInstitution" />
                                    </h:selectOneListbox>
                                    <h:outputText value="Fee"/>
                                    <h:inputText autocomplete="off" id="txtFee" value="#{timedItemFeeController.currentFee.fee}"/>
                                    <h:outputLabel value="Duration Hour"/>
                                    <h:inputText autocomplete="off" value="#{timedItemFeeController.currentFee.durationHours}"/>
                                    <h:outputLabel value="Over Shoot Hour"/>
                                    <h:inputText autocomplete="off" value="#{timedItemFeeController.currentFee.overShootHours}"/>
                                    <h:outputLabel value=""/>
                                    <p:selectBooleanCheckbox value="#{timedItemFeeController.currentFee.booleanValue}"
                                                             itemLabel="Consider Each Unit"/>
                                    <h:outputText value=""/>
                                    <h:commandButton id="btnAddTo" value="Add" 
                                                     action="#{timedItemFeeController.saveCharge}" styleClass="buttons">

                                    </h:commandButton>
                                </h:panelGrid>

                                <p:dataTable id="dtbFee" rowIndexVar="rowIndex" value="#{timedItemFeeController.charges}" var="bi" >
                                    <p:column headerText="Fee Name">
                                        <p:inputText value="#{bi.name}" autocomplete="off" />
                                    </p:column>
                                    <p:column headerText="Fee">
                                        <p:inputText value="#{bi.fee}" autocomplete="off" />
                                    </p:column>
                                    <p:column headerText="Duration Hour">
                                        <p:inputText value="#{bi.durationHours}" autocomplete="off" />
                                    </p:column>
                                    <p:column headerText="Over Shoot">
                                        <p:inputText value="#{bi.overShootHours}" autocomplete="off" />
                                    </p:column>
                                    <p:column headerText="Update">
                                        <p:commandButton id="update" ajax="false" value="Update" action="#{timedItemFeeController.updateFee(bi)}" >
                                        </p:commandButton>
                                    </p:column>
                                    <p:column headerText="Remove">
                                        <h:commandButton id="remove" value="Remove" action="#{timedItemFeeController.removeFee}" >
                                            <f:setPropertyActionListener value="#{bi}" target="#{timedItemFeeController.removedTimedItemFee}"/>
                                            <p:ajax update=":#{p:component('lblTotal')} dtbFee"  process="remove dtbFee" />
                                        </h:commandButton>
                                    </p:column>
                                </p:dataTable>

                            </p:panel>

                        </h:panelGrid>

                    </h:panelGrid>





                </p:panel>
            </h:form>

        </h:panelGroup>
    </ui:define>


</ui:composition>
